'''gaoyunzhi@gmail.com
1:14 PM 10/15/2012
sysPath
change path according to the system
deal with windows and non-windows
input: windoes path
output: path according to the system

folderPath:
make a folderPath with ending / or \, at the same time, change according to the system.
'''
import os
import platform

def sysPath(path):
    if os.name=='nt' or platform.uname()[1][-15:-9]=='equity':
        path=path.replace('\ '[:1],'/ '[:1])
    else:
        path=path.replace('/ '[:1],'\ '[:1])
        
    return path

def folderPath(path):
    path=path.strip()
    if path=='': return path
    if path[-1]!='/' and path[-1]!='\ '[:-1]:
        path=path+'/'
    return sysPath(path)

def testSysPath():
    print sysPath('C:\Users\gyz\Dropbox\classes\ml\HW2\code')
    print sysPath('C:\Users\gyz\Dropbox\classes\ml\HW2\code\ '[:-1])
    print sysPath('C:/Users\gyz\Dropbox\classes\ml\HW2\code\ '[:-1])

def testFolderPath():
    print folderPath('C:\Users\gyz\Dropbox\classes\ml\HW2\code')
    print folderPath('C:\Users\gyz\Dropbox\classes\ml\HW2\code\ '[:-1])
    print folderPath('C:/Users\gyz\Dropbox\classes\ml\HW2\code\ '[:-1])
                  
if __name__=='__main__':
    print 'change path according to the system\ndeal with windows and non-windows'
    print 'some tests, run on windows, still need some chance to run this on linux'
    testSysPath()
    print 'make a folderPath with ending / or \  '
    print 'some tests, run on windows, still need some chance to run this on linux'
    testFolderPath()
    
